import numpy as np

class Solution:
    def grayCode(self, n: int):
        li = np.array([0, 1, 3, 2])
        if n >= 3:
            for i in range(2,n):
                li_to = li[::-1] | pow(2, i)
                # print(li_to)
                li = np.hstack((li, li_to))
            return li.tolist()
        elif n == 2:
            return li.tolist()
        elif n == 1:
            return np.array([0, 1]).tolist()
        else:
            return np.array([0]).tolist()

# if __name__ == '__main__':
#     s = Solution()
#     res = s.grayCode(3)
#     print(res)
#
# '''
# 00 - 0
# 01 - 1
# 11 - 3
# 10 - 2
# 110
# 111
# 101
# 100
# '''